//
//  SSSMerchantTodayBenefitViewController.m
//  SSSAllRollAgency
//
//  Created by xnxin on 2017/3/15.
//  Copyright (c) 2017 Darker. All rights reserved.
//

#import "SSSMerchantTodayBenefitViewController.h"
#import "SSSMerchantTodayBenefitViewCellModel.h"
#import "UIView+XHAdd.h"
#import "XHKitMacro.h"
#import "XHUIHelper.h"
#import "APITool.h"
#import "NSDateAddition.h"
#import "NSDictionaryAdditions.h"
#import "XHTableViewSection.h"
#import "SSSMerchantTodayBenefitViewCell.h"

@interface SSSMerchantTodayBenefitViewController ()

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UILabel *todayBenefitLabel;
@property (nonatomic, strong) NSString *todayBenefit;

@end

@implementation SSSMerchantTodayBenefitViewController

- (void)viewDidLoad {
//    self.networkHelper.params[@"queryDate"] = [[NSDate date] xhstringWithFormat:@"yyyy-MM-dd" timeZone:nil
//                                                                         locale:[NSLocale localeWithLocaleIdentifier:@"GMT+8"]];
    self.networkHelper.params[@"queryDate"] = @"2017-04-05";
    [super viewDidLoad];

    self.tableView.rowHeight = 75;
    self.tableView.left = 15;
    self.tableView.width = DEVICE_WIDTH - 30;

    self.tableView.backgroundColor = self.view.backgroundColor;

    self.tableView.tableHeaderView = self.headerView;
    self.todayBenefit = @"0";
    self.tableView.allowsSelection = NO;
}


- (NSArray<NSString *> *)nibNameArray {
    return @[@"SSSMerchantTodayBenefitViewCell"];
}


#pragma mark - getter

- (UIView*)headerView {

    if (!_headerView) {

        _headerView = [UIView new];
        _headerView.height = 36;
        _headerView.width = DEVICE_WIDTH - 30;
        _headerView.backgroundColor = [UIColor whiteColor];

        [_headerView addSubview:self.todayBenefitLabel];

        UIView *line = [XHUIHelper sepreateLineWithY:35.5];
        line.left = 12;
        line.width = _headerView.width - 24;
        [_headerView addSubview:line];
    }
    return _headerView;
}

- (UILabel *)todayBenefitLabel {

    if (!_todayBenefitLabel) {

        _todayBenefitLabel = [UILabel new];
        _todayBenefitLabel.font = [UIFont systemFontOfSize:14];
        _todayBenefitLabel.textColor = [UIColor colorWithHex:@"57C18B"];
    }
    return _todayBenefitLabel;
}

- (NSString *)url {
    return [APITool urlStr:@"/bApi/myIncome/dayIncome"];
}

#pragma mark -setter

- (void)setTodayBenefit:(NSString *)todayBenefit {
    _todayBenefit = todayBenefit;

    self.todayBenefitLabel.text = [NSString stringWithFormat:@"总额: %@", todayBenefit];
    [self.todayBenefitLabel sizeToFit];
    self.todayBenefitLabel.centerX = self.headerView.width/2;
    self.todayBenefitLabel.centerY = self.headerView.height/2;
}

- (NSArray*)processData:(NSDictionary *)data {

    self.todayBenefit = [[data objectOrNilForKey:@"totalIncome"] description];
    NSArray *modelArray = [NSArray modelArrayWithClass:[SSSMerchantTodayBenefitViewCellModel class]
                                                  json:[[data objectOrNilForKey:@"page"] objectOrNilForKey:@"pageList"]];
    return modelArray;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(SSSMerchantTodayBenefitViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([self.dataSource isLastCellForIndexPath:indexPath]) {
        cell.hidenGrayLine = YES;
    }
}
@end
